<?php

namespace app\index\model;
use think\Cache;
use think\Db;
use \think\Model;
class Article extends Model
{

//    获取对应分类下的文章
    public function getcatearticle($id)
    {
        $cate = new Cate();
        $res = $cate->getchilredid($id);
        $articleres = db('article')->where("cate_id IN($res)")->order('id desc')->paginate(5);
        return $articleres;
    }

//    获取热门文章
    public function gethotarticle($id)
    {
        $cate = new Cate();
        $res = $cate->getchilredid($id);
        $articleres = db('article')->where("cate_id IN($res)")->order('click desc')->limit(4)->select();
        return $articleres;
    }


//    文章对分类是多对一
    public function cate(){
        return $this->belongsTo('cate_id','cate_id');
    }

}
